package net;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @Author Justin Parker
 * @Date 2024/7/18 0018 16:20
 * @Version 1.0
 */
/*
    网络端的服务器对象
 */
public class NetServer {
    public static void main(String[] args) throws Exception{
        //1.构建ServerSocket对象，并在8080端口进行监听
        ServerSocket serverSocket = new ServerSocket(8080);
        System.out.println("服务器启动成功，等待服务器连接..........");
        //2.通过accept方法获取Socket对象
        Socket socket = serverSocket.accept();  //阻塞式方法
        System.out.println("服务器已连接，Client:"+socket);
        //3.获取输入流对象
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));

//        InputStream is = socket.getInputStream();
        //
        String a = br.readLine();
//        int a = is.read();
        //
        System.out.println("接受到客户端发过来的数据："+a);


    }
}
